#include <iostream>
#include <type_traits>
using namespace std;
class Fibonacci{
    public:
    Fibonacci(int n)
    :_n(n)
    {
    }
    void form()
    {
        int _flag = 0;
        while(_n < arr[_flag])
        {
            if(_flag == 0)
            {
                arr[_flag] = 0;
                _flag++;
            }
            if(_flag == 1)
            {
                arr[_flag] = 1;
                _flag++;

            }
            if(_flag >= 2)
            {
                arr[_flag] = arr[_flag-2] + arr[_flag-1];
                _flag++;

            }
        }
    }
    int compare()
    {
        if(arr[_flag] - _n < _n - arr[_flag-1]) // 最大值路径短返回一
        {
            return 1;
        }
        else if(arr[_flag] - _n > _n - arr[_flag-1])//最小值路径短返回零
        {
            return 0;
        }
        if(arr[_flag == _n]) //相等返回2
        {
            return 2;
        }
        return 3;
    }
    int getpnum()
    {
        
        int i = compare();
        if(i == 2)
        {
            return 0;
        }
        if(i == 3)
        {
            return 3;
        }
        int getnum = 0;
        if(i == 1)
        {
            while(_n != arr[_flag])
            {
                _n++;
                getnum++;
            }
            return getnum;
        }
        else if(i == 0){
        while(_n != arr[_flag-1])
        {
            _n--;
            getnum++;
        }
        return getnum;
        }
        return 3;
    }
    private:
    int* arr = nullptr;
    int _n;
    int _flag = 0;
};
int main() {
  
int n = 0;
cin >> n;
Fibonacci test(n);
test.form();
test.form();
cout << test.getpnum();
}
// 64 位输出请用 printf("%lld")